/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class ctlr_AccountLocation_Test
{

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        //accountObject.LicenseNumber__c = serialObject.id;
        accountObject.License_Application_Step__c = 'Archived';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Trading - One Activity';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.Master_Account_Flag__c = true;
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        insert accountObject;
        
        
        //For Location Object Records...
        Location__c locationObject1 = new Location__c();
        locationObject1.Name = 'Test Office';
        locationObject1.Location_Type__c = 'Office';
        locationObject1.Rental_Rate__c = 18000;
        insert locationObject1;
        
        //For Location Object Records...
        Location__c locationObject2 = new Location__c();
        locationObject2.Name = 'Test Office 12345';
        locationObject2.Location_Type__c = 'Office';
        locationObject2.Rental_Rate__c = 18000;
        insert locationObject2;
        
        //For Tenancy Object Records...
        RecordType newTenancyRecordType = [select Id,IsActive,SObjectType,DeveloperName from RecordType where DeveloperName = 'New_Tenancy_Contract' AND SObjectType = 'Tenancy_Contract__c'];
        Tenancy_Contract__c tenancyObject1 = new Tenancy_Contract__c();
        tenancyObject1.Location__c = locationObject1.id;
        tenancyObject1.RecordTypeId = newTenancyRecordType.id;
        tenancyObject1.Tenant__c = accountObject.id;
        tenancyObject1.Tenancy_Contract_Start_Date__c = accountObject.License_Issue_Date__c;
        tenancyObject1.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(1).adddays(-1);
        insert tenancyObject1;
        
        
        Tenancy_Contract__c tenancyObject2 = new Tenancy_Contract__c();
        tenancyObject2.Location__c = locationObject2.id;
        tenancyObject2.RecordTypeId = newTenancyRecordType.id;
        tenancyObject2.Tenant__c = accountObject.id;
        tenancyObject2.Tenancy_Contract_Start_Date__c = accountObject.License_Issue_Date__c;
        tenancyObject2.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(1).adddays(-1);
        insert tenancyObject2;
        
        
        //Updating with the current Tenancy Contract Field...
        //locationObject1.Current_Tenancy_Contract__c = tenancyObject1.Id;
        //update locationObject1;
        
        //Updating with the current Tenancy Contract Field...
        //locationObject2.Current_Tenancy_Contract__c = tenancyObject2.Id;
        //update locationObject2;
        
        //Now For Account Locations ....
        Account_Location__c accountLocationObject1 = new Account_Location__c();
        accountLocationObject1.Account__c = accountObject.Id;
        accountLocationObject1.Previous_Location__c = locationObject1.Id;
        accountLocationObject1.Previous_Tenancy_Contract__c = tenancyObject1.Id;
        insert accountLocationObject1;
        
        Account_Location__c accountLocationObject2 = new Account_Location__c();
        accountLocationObject2.Account__c = accountObject.Id;
        accountLocationObject2.Previous_Location__c = locationObject2.Id;
        accountLocationObject2.Previous_Tenancy_Contract__c = tenancyObject2.Id;
        insert accountLocationObject2;
        
        //Account Id Standard Controller...
        ApexPages.StandardController accountExtendedObject = new ApexPages.StandardController(accountObject);
        ApexPages.CurrentPage().getParameters().put('id',accountObject.id);
        
        ctlr_AccountLocation accountLocationClass = new ctlr_AccountLocation(accountExtendedObject);
        
        accountLocationClass.generateAccountLocationModule();
        accountLocationClass.additems();
        accountLocationClass.RowIndex = 'j_id0:MainForm:j_id50:0:j_id52:0:EDITID';
        
        //amendmentActivityClass.ReceiptWrapper  wrapperClass = new amendmentActivityClass.ReceiptWrapper(amendmentObject.Name,'Company_Amendment_Change_License_Type', 2, amendmentObject.id);
        accountLocationClass.EditAllow();
        accountLocationClass.updateitemlist();
        accountLocationClass.cancelEdit();
        accountLocationClass.RowIndex = 'j_id0:MainForm:j_id50:0:j_id52:0:EDITID';
        accountLocationClass.DelAllow();
        
        
        
    }
}